<template>
    <div class="hall">
      <!--nav-->
      <div class="Nav">
        <Nav></Nav>
      </div>
      <!--/nav-->

      <div class="content">
        <div class="movie_content" style="width: 960px;height:800px;">
          <!--搜索框-->
          <div class="search" style="margin-top: 10px">
            <el-input v-model="input" placeholder="请输入内容" style="width: 500px;margin-left: 200px"  class="input-with-select">
              <el-button slot="append" icon="el-icon-search" @click="selectFilm()"> 搜索</el-button>
            </el-input>
          </div>
          <!--导航条-->
          <div class="header_list">
            <div class="main_list" >
              <span><a href="" @click.prevent="findAll()">全部</a></span>
              <el-dropdown @command="handleCommand">
                    <span class="el-dropdown-link">
                      选择其他类别<i class="el-icon-arrow-down el-icon--right"></i>
                    </span>
                <el-dropdown-menu  slot="dropdown">
                  <el-dropdown-item  v-for="(item,index) in FilmCategory" :command="item.id" :key="index">{{item.name}}</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </div>
          </div>
          <div>
            <!--内容区域-->
            <div class="movie_list">
              <div  v-for="(item,index) in tableData.slice((currentPage-1)*pageSize,currentPage*pageSize)">
                <el-card @click.native="toScore(item.id)"  :body-style="{ padding: '0px' }" class="card" style="width: 200px;height: 250px;float: left" shadow="hover">
                  <div style="width: 100px;height: 20px;margin-left: 60px;padding: 2px;">
                    <span>{{item.name}}</span>
                  </div>
                  <img   style="width: 150px;height: 180px;margin-left: 25px;margin-top: 5px" :src="'static/img/'+item.img" alt="">
                  <div style="width:180px;height: 20px;margin-left: 10px;padding: 2px;margin-top: 5px">
                    <span style="font-size: 10px">{{item.actors}}</span>
                  </div>
                </el-card>
              </div>
            </div>
            <el-divider></el-divider>
            <!--分页-->
            <el-pagination
              background
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-size="pageSize"
              layout="total, prev, pager, next"
              :total="tableData.length">
            </el-pagination>
          </div>
        </div>
      </div>

      <!--Footer-->
      <div class="footer">
        <Footer></Footer>
      </div>
      <!--/Footer-->
    </div>
</template>

<script>
  import Nav from "../components/Nav";
  import Footer from "../components/Footer";
    export default {
      name: "Hall",
      data(){
        return{
          input:'',
          data:'',
          currentPage: 1, //初始页
          pageSize: 12,    //每页的数据
          tableData: [{}],/*查询到的数据*/
          FilmCategory:[{}],
          formLabelWidth: '100px',
        }
      },
      methods:{
        // 初始页currentPage、初始每页数据数pagesize和数据data
        handleSizeChange: function (size) {
          this.pagesize = size;
          console.log(this.pagesize)  //每页下拉显示数据
        },
        handleCurrentChange: function (currentPage) {
          this.currentPage = currentPage;
          console.log(this.currentPage)  //点击第几页
        },
        findAll() {
          let _this = this
          this.$axios.get("http://localhost:8088/film/getFilm").then(function (res) {
            _this.tableData = res.data
            console.log(_this.tableData)
          }).catch(function (err) {
            alert('查询失败')
          })
        },
        /*查询类别*/
        findCategory(){
          let _this = this
          this.$axios.get("http://localhost:8088/category/getFilmCategory").then(function (res) {
            _this.FilmCategory = res.data
            console.log(_this.FilmCategory)
          }).catch(function (err) {
            alert('查询失败')
          })
        },
        /*根据id分类查询电影*/
        handleCommand(command) {
          let _this = this
          this.$axios.post("http://localhost:8088/film/getClassFilm/"+command).then(function(res){
            _this.tableData = res.data
          }).catch(function (err) {
            alert('查询失败')
          })
        },
        /*模糊查询*/
        selectFilm(){
          let _this = this
          if(this.input==''){
            location.reload()
            return false;
          }
          this.$axios.post("http://localhost:8088/film/selectFilm/"+this.input).then(function(res){
            _this.tableData = res.data
            console.log(res.data)
          }).catch(function (err) {
            alert('查询失败')
          })
        },
        /*前往评分界面*/
        toScore(id){
          this.$router.push({name:'Score',query:{id:id}})
        }
      },
      components:{
        Nav,
        Footer
      },
      mounted() {
        this.findAll()
        this.findCategory()
        window.scrollTo(0,0)
      }
    }
</script>
<style scoped>
  .card span{
    word-break: break-all;
    text-overflow: ellipsis;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
  }

  .card{
    margin-left: 30px;
    margin-top: 20px;
  }


  .movie_list{
    height: 800px;
  }


  .el-dropdown-link {
    cursor: pointer;
    color: white;
  }
  .el-icon-arrow-down {
    font-size: 12px;
  }


  .main_list span{
    margin-left: 32px;
    font-size: 20px;
  }

  .main_list a{
    text-decoration: none;
    color: white;
  }

  .main_list a:hover{
    color: rgba(228,228,228,0.94);
  }

  .main_list{
    padding-top: 10px;
    width: 960px;
    height: 40px;;
    margin-top: 20px;
    background-color: rgba(31,160,255,0.94);
    border-radius: 5px;
  }

  .content{
    padding: 20px;
    border-radius: 5px;
    width: 960px;
    height: 1000px;
    background-color: white;
    margin-top: 20px;
    margin-left: 270px;
    margin-bottom: 10px;
  }
  .hall{
    width: 100%;
    height: 1140px;
    background-color: rgba(238,236,237,0.94);
  }
</style>
